package c.c.k.service.impl;

import c.c.k.config.StockConfig;
import c.c.k.pojo.Fund;
import c.c.k.pojo.FundStock;
import c.c.k.repository.FundRepository;
import c.c.k.service.FundBaseService;
import c.c.k.service.FundService;
import c.c.k.service.FundStockService;
import c.c.k.util.BeanUtil;
import c.c.k.util.StockUtil;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by chenck on 2022/3/19.
 */
@Service
@Slf4j
public class FundServiceImpl implements FundService {
    @Autowired
    private FundRepository fundRepository;
    @Autowired
    private StockConfig stockConfig;
    @Autowired
    private FundBaseService fundBaseService;
    @Autowired
    private FundStockService fundStockService;

    @Override
    public List<Fund> listFund() {
        return fundRepository.findAll();
    }

    @Override
    public List<Fund> listFund(List<Long> ids) {
        return fundRepository.findAllById(ids);
    }

    @Override
    public void initFund() {
        //fundBaseService.li
        List<Long> collect = fundStockService.listByGtPercent(8D).stream().map(FundStock::getFundId).collect(Collectors.toList());
        fundBaseService.listAll(collect).forEach(fundBase -> {
            fundRepository.save(BeanUtil.transfrom(Fund.class, fundBase));
        });
    }
}
